{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from pathlib import Path\n",
    "from tqdm import tqdm\n",
    "from data.utils import read_record, load_patient_data\n",
    "import matplotlib.pyplot as plt\n",
    "import wfdb\n",
    "import h5py\n",
    "\n",
    "from training.train_transformer import load_chunk_of_data\n",
    "from data.hdf5_dataset import HDF5Dataset\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "FOLDER = Path('/home/timodw/IDLab/Digihealth-Asia/cardiovascular_monitoring/ugent/heartbeat_classification/processed_data/training_snapshots/mit-full')\n",
    "mit = HDF5Dataset(FOLDER / 'train.hdf5', input_type='cwt')\n",
    "incart = HDF5Dataset(FOLDER / 'val.hdf5', input_type='cwt')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading chunk of size 1,000...\n",
      "Loading took 2.12s\n",
      "\n",
      "Loading chunk of size 1,000...\n",
      "Loading took 1.85s\n",
      "\n"
     ]
    }
   ],
   "source": [
    "X_mit, rr_mit, y_mit = load_chunk_of_data(mit, 1000)\n",
    "X_incart, rr_incart, y_incart = load_chunk_of_data(incart, 1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((tensor(-1.), tensor(3.8629), tensor(0.0003), tensor(0.9988)),\n",
       " (tensor(-1.), tensor(2.8521), tensor(0.0023), tensor(0.9937)))"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(X_mit.min(), X_mit.max(), rr_mit.min(), rr_mit.max()), (X_incart.min(), X_incart.max(), rr_incart.min(), rr_incart.max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image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OD6OjoQENDAwCgoaEBAwMD6OzstNIcPnwYuq6jvr5+OrNDREREPjXlHpSLFy/izJkz1vtz586hq6sLs2bNQk1NDTZt2oRf/OIXWLBgAWpra7F161ZUV1fjrrvuAgDccMMNuP322/HQQw9h9+7dSCQSaG5uxtq1azmDh4iIiABcRYBy/PhxfPWrX7Xem2NDmpqa8Mwzz+CRRx7BpUuXsG7dOgwMDOC2227DwYMHUVpaam2zZ88eNDc3Y+XKldA0Dffccw927tw56TyEw2E8+uijrpd9KP9YH97BuvAO1oV3sC78Sclk5voQERER5RGfxUNERESewwCFiIiIPIcBChEREXkOAxQiIiLyHF8GKLt27cL8+fNRWlqK+vp6HD16tNBZKiqtra245ZZbcN1116Gqqgp33XUXTp065Uhz5coVbNiwAbNnz8bMmTNxzz33oLe315Gmu7sba9aswYwZM1BVVYWHH34YyWQyn6dSdHbs2AGlFDZt2mQtY13k1wcffIDvfOc7mD17NsrKyrB48WIcP37cWi8i2LZtG+bMmYOysjLE43GcPn3asY/+/n40NjaivLwckUgEDz74IC5evJjvU/G1VCqFrVu3ora2FmVlZfj85z+Pxx9/3PGMF9aFz4nP7N27V0KhkPzxj3+UkydPykMPPSSRSER6e3sLnbWisWrVKnn66aflxIkT0tXVJXfccYfU1NTIxYsXrTTr16+XuXPnSltbmxw/fly+/OUvy6233mqtTyaTsmjRIonH4/Lmm2/KgQMHpLKyUrZs2VKIUyoKR48elfnz58uXvvQl2bhxo7WcdZE//f39Mm/ePLnvvvuko6NDzp49K//85z/lzJkzVpodO3ZIRUWF7Nu3T9566y35xje+IbW1tXL58mUrze233y5LliyR119/Xf71r3/JF77wBbn33nsLcUq+tX37dpk9e7bs379fzp07Jy+88ILMnDlTfvvb31ppWBf+5rsAZfny5bJhwwbrfSqVkurqamltbS1gropbX1+fAJBXX31VREQGBgakpKREXnjhBSvNu+++KwCkvb1dREQOHDggmqZJT0+Pleapp56S8vJyGR4ezu8JFIGhoSFZsGCBHDp0SL7yla9YAQrrIr9+8pOfyG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IWiznqY3BwEB0dHY76GBgYQGdnp5Xm8OHD0HUd9fX1eTiL4vDxxx9D05xNWCAQgK7rAFgXRaHQo3Snau/evRIOh+WZZ56Rd955R9atWyeRSMQxQ4Guzfe+9z2pqKiQV155RT788EPr9fHHH1tp1q9fLzU1NXL48GE5fvy4NDQ0SENDg7XenNr6ta99Tbq6uuTgwYPymc98hlNbp4F9Fo8I6yKfjh49KsFgULZv3y6nT5+WPXv2yIwZM+TZZ5+10uzYsUMikYi89NJL8u9//1vuvPNO16mtS5culY6ODjly5IgsWLCAU1unqKmpST772c9a04z/+te/SmVlpTzyyCNWGtaFv/kuQBERefLJJ6WmpkZCoZAsX75cXn/99UJnqagAcH09/fTTVprLly/L97//ffn0pz8tM2bMkLvvvls+/PBDx37+85//yOrVq6WsrEwqKyvlxz/+sSQSiTyfTfHJDFBYF/n197//XRYtWiThcFgWLlwov//97x3rdV2XrVu3SjQalXA4LCtXrpRTp0450vzvf/+Te++9V2bOnCnl5eVy//33y9DQUD5Pw/cGBwdl48aNUlNTI6WlpfK5z31OfvaznzmmzrMu/E2J2G67R0REROQBvhqDQkRERJ8MDFCIiIjIcxigEBERkecwQCEiIiLPYYBCREREnsMAhYiIiDyHAQoRERF5DgMUIiIi8hwGKEREROQ5DFCIiIjIcxigEBERkecwQCEiIiLP+X8Nb4MS4+vxxQAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAigAAABjCAYAAACxDfsDAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAUyElEQVR4nO3df2wUZf4H8PfM7I8Woa1Qu0tPCvUkwRNEjkqvamIMm0Mk589cDlMvFY1EpXdwvYjUOzDmjiu5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eFDmzp3Lqa2jVFNTI9/73vesacavvvqqFBcXy/r1660ybAtv81xAERF59tlnpaysTAKBgCxZskTee+89p6uUUwBkfLzwwgtWmfPnz8tjjz0ml19+uUyZMkXuvvtuOXPmjG07X331lSxfvlzy8/OluLhYfv3rX0ssFsvy3uSe9IDCtsiuN954Q+bPny/BYFDmzZsnf/vb32zrlVKyceNGCYVCEgwGZenSpXL8+HFbmW+//Vbuu+8+mTp1qhQUFMiqVaukp6cnm7vhed3d3bJ27VopKyuTvLw8ueqqq+Q3v/mNbeo828LbNJGU2+4RERERuYCnxqAQERHR5MCAQkRERK7DgEJERESuw4BCRERErsOAQkRERK7DgEJERESuw4BCRERErsOAQkRERK7DgEJERESuw4BCRERErsOAQkRERK7DgEJERESu8//PrRT5EHuFIgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "plt.imshow(X_mit[42].T)\n",
    "plt.show()\n",
    "plt.imshow(X_incart[543].T)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "Dimension out of range (expected to be in range of [-1, 0], but got 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[43], line 2\u001b[0m\n\u001b[1;32m      1\u001b[0m mask \u001b[38;5;241m=\u001b[39m X_mit \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0.\u001b[39m\n\u001b[0;32m----> 2\u001b[0m X_min, X_max \u001b[38;5;241m=\u001b[39m \u001b[43mX_mit\u001b[49m\u001b[43m[\u001b[49m\u001b[43mmask\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmin\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdim\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m, X_mit[mask]\u001b[38;5;241m.\u001b[39mmax(dim\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m)\n\u001b[1;32m      3\u001b[0m X_min\n",
      "\u001b[0;31mIndexError\u001b[0m: Dimension out of range (expected to be in range of [-1, 0], but got 1)"
     ]
    }
   ],
   "source": [
    "mask = X_mit >= 0.\n",
    "X_min, X_max = X_mit[mask].min(dim=1), X_mit[mask].max(dim=0)\n",
    "X_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tensor([[ 0.4559,  0.5180,  0.5785,  ...,  0.3503,  0.3343,  0.0000],\n",
       "        [ 0.4787,  0.5141,  0.5938,  ...,  0.3293,  0.3346,  0.0100],\n",
       "        [ 0.4335,  0.5039,  0.5666,  ...,  0.3165,  0.3339,  0.0200],\n",
       "        ...,\n",
       "        [-1.0000, -1.0000, -1.0000,  ..., -1.0000, -1.0000, -1.0000],\n",
       "        [-1.0000, -1.0000, -1.0000,  ..., -1.0000, -1.0000, -1.0000],\n",
       "        [-1.0000, -1.0000, -1.0000,  ..., -1.0000, -1.0000, -1.0000]])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = X_mit[0]\n",
    "index = (X[:, -1] < .0).nonzero()[0]\n",
    "X_min, X_max = X[:index, :-1].min(), X[:index, :-1].max()\n",
    "X[:index, :-1] -= X_min\n",
    "X[:index, :-1] /= X_max - X_min\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
